import { watch } from "vue";
import { onShow } from "@dcloudio/uni-app";
import { useCartStore } from "@/store/cart";

export const mixTabber = () => {
    const cartStore = useCartStore();
    // 为tabBar设置数字徽标
    const setBadge = () => {
        // 调用 uni.setTabBarBadge() 方法，为购物车设置右上角的徽标
        uni.setTabBarBadge({
            index: 2, // 索引
            text: cartStore.total + "", // 注意：text 的值必须是字符串，不能是数字
        });
    };

    watch(
        () => cartStore.total,
        () => {
            setBadge();
        }
    );

    onShow(() => {
        setBadge();
    });
};
